package com.gage.commons.result;

import java.io.Serializable;
import java.util.Date;

public class BaseConditionVO implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3977089285405421628L;
	public final static int PAGE_SHOW_COUNT = 20; // 每页显示多少条数据
	private int page = 1; // 第几页
	private int rows = 0; 
	private int totalCount = 0; // 查询数据总条数
	private int totalPages=1; // 查询数据总页数
	private String sort; 
	private String order; // 排序（升序或降序）
	private String keywords; // 模糊查询关键词
	private String status; 
	private String type;
	private Date startDate;
	private Date endDate; 

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	public String getType() {
		return "".equals(type) ? null : type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getStatus() {
		return "".equals(status)? null : status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public int getPage() {
		page=page <1 ? 1 : page;
		page=page > getTotalPages() ? getTotalPages() : page;
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows > 0 ? rows : PAGE_SHOW_COUNT;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	
	public String getSort() {
		return sort;
	}
	public void setSort(String sort) {
		this.sort = sort;
	}
	public String getOrder() {
		return "desc".equals(order) ? "desc" : "asc";
	}
	public void setOrder(String order) {
		this.order = order;
	}
	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	
	public String getKeywords() {
		return "".equals(keywords)? null : keywords;
	}
	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}
	
	public int getStartIndex() {
		int pageNum = this.getPage() > 0 ? this.getPage() - 1 : 0;
		return pageNum * this.getRows();
	}
	public int getTotalPages()
	{
		//return (int)Math.ceil(getTotal() / getPageSize());
		int pageCount =(int)Math.ceil((getTotalCount() / getRows()));
		if (getTotalCount() % getRows() > 0) {
			pageCount ++;
		}
		totalPages=pageCount;
		return totalPages;
	}
}
